package com.zjtaixue.usersite.service.impl;

import com.zjtaixue.usersite.domain.College;
import com.zjtaixue.usersite.mapper.CollegeMapper;
import com.zjtaixue.usersite.page.PageResult;
import com.zjtaixue.usersite.query.CollegeQueryObject;
import com.zjtaixue.usersite.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("collegeService")
public class CollegeServiceImpl implements CollegeService {
    @Autowired
    private CollegeMapper collegeMapper;
    @Override
    public PageResult<College> listPageResult(CollegeQueryObject qo) {
        int count = collegeMapper.queryCount(qo);
        if (count > 0) {
            return new PageResult<College>(collegeMapper.query(qo), qo.getCurrentPage(), count, qo.getPageSize());
        }
        return PageResult.empty(qo.getPageSize());
    }

    @Override
    public int insert(College college) {
        return collegeMapper.insert(college);
    }

    @Override
    public College getById(Integer id) {
        return collegeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(College college) {
        collegeMapper.updateByPrimaryKey(college);
    }

    @Override
    public int deleteById(Integer id) {
        return collegeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<College> listAllColleges() {
        return collegeMapper.selectAll();
    }
}
